#!/bin/bash
#
#  Auto build shell script for openplatform
#  Create by Lytsing Huang 2015-04-28
#

if [ $# -lt 1 ]; then
  echo "Usage: $0 [p|t|d]";
  exit;
fi

CONFIG=''

case $1 in
  p | production)
    cp -f "openplatform-base-webapp/src/main/resources/production/application.properties" "openplatform-base-webapp/src/main/resources/application.properties"
    cp -f "openplatform-base-webapp/src/main/resources/production/logback.xml" "openplatform-base-webapp/src/main/resources/logback.xml"
   
    ;;
  pre | preproduction)
  cp -f "openplatform-base-webapp/src/main/resources/production/application.properties" "openplatform-base-webapp	/src/main/resources/application.properties"
  cp -f "openplatform-base-webapp/src/main/resources/production/logback.xml" "openplatform-base-webapp/src/main/resources/logback.xml"
  
	;;
  t | test)
    cp -f "openplatform-base-webapp/src/main/resources/test/application.properties" "openplatform-base-webapp/src/main/resources/application.properties"
    cp -f "openplatform-base-webapp/src/main/resources/test/logback.xml" "openplatform-base-webapp/src/main/resources/logback.xml"
    
    ;;
  d | devleopment)
    CONFIG="src/main/portable/dev.xml"
    ;;
  *)
    echo "Error! unknown parameter."
    exit 1
    ;;
esac

# 此处需要设置或修改MAVEN_OPTS，否则在执行mvn install命令时可能会出现OutOfMemoryError错误
export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m"

# -U：含义：该参数能强制让Maven检查所有SNAPSHOT依赖更新，确保集成基于最新的状态，如果没有该参数，
# Maven默认以天为单位检查更新，而持续集成的频率应该比这高很多
mvn clean install -Dmaven.test.skip=true -Dmaven.compile.fork=true -U